// https://www.acwing.com/problem/content/9/

#include <iostream>
#include <vector>

using namespace std;

int solution(int maxVolume, vector<int>& groups, vector<vector<int>>& volumesGroup, vector<vector<int>>& valuesGroup) {
    vector<int> dp(maxVolume + 1);
    const auto n = volumesGroup.size();
    dp[0] = 0;
    for (int i=0; i<n; i++) {
        for (int j=maxVolume; j>=0; j--) {
            for (int g=0; g<groups[i]; g++) {
                if (j >= volumesGroup[i][g]) {
                    dp[j] = max(dp[j], dp[j-volumesGroup[i][g]] + valuesGroup[i][g]);
                }
            }
        }
    }

    return dp[maxVolume];
}



int main() {
    int n, maxVolume;
    cin>>n>>maxVolume;
    // 每组的大小
    vector<int> groups(n);
    vector<vector<int>> volumesGroup(n);
    vector<vector<int>> valuesGroup(n);

    for (int i=0; i<n; i++) {
        cin>>groups[i];
        for (int j=0; j<groups[i]; j++) {
            int v1, v2;
            cin>>v1>>v2;
            volumesGroup[i].push_back(v1);
            valuesGroup[i].push_back(v2);
        }
    }

    cout<<solution(maxVolume, groups, volumesGroup, valuesGroup)<<endl;

    return 0;
}
